<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function selectSort( arr ){
            for ( var i = 0 ; i < arr.length ; i ++ ) {
                var minIndex = i ;
                for ( var j = i ; j < arr.length ; j ++ ) {
                    if ( arr[minIndex] > arr[j] ) {
                        minIndex = j ; 
                    }
                }
                var temp = arr[minIndex] ;
                arr[minIndex] = arr[i] ; 
                arr[i] = temp ;
            }
            return arr ; 
        }
        var arr = [1,2,4,754,785,4,45,32,86,87,45,87,31,8,21,84,465,1867];
        console.log(selectSort(arr));
    </script>
</body>
</html>